﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface.Presentation.Controls;
using TouchControls;

namespace TouchMenuSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : SurfaceWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            for (int r = 0; r < SampleGrid.RowDefinitions.Count; r++)
            {
                for (int c = 0; c < SampleGrid.ColumnDefinitions.Count; c++)
                {
                    var menu = CreateMenu();
                    if (r==0)
                        menu.VerticalAlignment = VerticalAlignment.Top;
                    if (r == SampleGrid.RowDefinitions.Count-1)
                        menu.VerticalAlignment = VerticalAlignment.Bottom;

                    if (c == 0)
                        menu.HorizontalAlignment = HorizontalAlignment.Left;
                    if (c == SampleGrid.ColumnDefinitions.Count - 1)
                        menu.HorizontalAlignment = HorizontalAlignment.Right;

                    SampleGrid.Children.Add(menu);
                    AdornmentGrid.SetRow(menu, r);
                    AdornmentGrid.SetColumn(menu, c);
                }
            }
        }

        private TouchMenu CreateMenu()
        {
            var res = new TouchMenu();
            for (int i = 0; i < 5; i++)
            {
                var item = this.GetChildMenu("Item " + i);
                item.MenuTileSize = 90;
                res.Items.Add(item);
                for (int j = 0; j < 5; j++)
                {
                    var childItem = this.AddChildMenu(item, "Item " + i + "-" + j);
                    childItem.MenuTileSize = 60;
                    for (int k = 0; k < 5; k++)
                    {
                        this.AddChildMenu(childItem, "Item " + j + "-" + k);
                    }
                }
            }
            return res;
        }

        private TouchMenuItem GetChildMenu(string text)
        {
            TouchMenuItem item = new TouchMenuItem();
            item.Header = text;
            return item;
        }

        private TouchMenuItem AddChildMenu(TouchMenuItem parent, string text)
        {
            var item = this.GetChildMenu(text);
            parent.Items.Add(item);
            return item;
        }
    }
}
